Page({
	data: {
		userInfo: {
			nickName: 'name',
			avatarUrl: '/icon/无头像.png'
		},
		showDialog: false,
		buttons: [{
				type: 'default',
				className: '',
				text: '拒绝',
				value: 0
			},
			{
				type: 'primary',
				className: '',
				text: '同意',
				value: 1,
				action: 'agree',
			}
		]
	},
	open: function () {
		this.setData({
			showDialog: true
		})
	},
	buttontap: function (event) {
		// console.log(this.data.buttons[1].text);
		// console.log(event.detail.item.text);
		// console.log(event.detail.item.text === this.data.buttons[1].text);
		if (event.detail.item.text === this.data.buttons[1].text) {
			wx.getUserProfile({
				desc: '用于完善资料',
				success: res => {
					console.log(res.userInfo);
					var userInfo = res.userInfo;
					var nickName = userInfo.nickName;
					var avatarUrl = userInfo.avatarUrl;
					this.setData({
						userInfo: {
							nickName: nickName,
							avatarUrl: avatarUrl
						}
					});
					const app = getApp();
					app.globalData.userInfo = userInfo;
				},
				fail: err => {
					console.error(err);
				}
			});
		}

		this.setData({
			showDialog: false
		});
	},

	navigateToSetting: function () {
		wx.navigateTo({
			url: '/pages/Setting/settings',
			success: function (res) {
				console.log("成功跳转到设置页面");
			},
			fail: function (err) {
				console.error("跳转到设置页面失败", err);
			}
		});
	},
	navigateTosaving: function () {
		wx.navigateTo({
			url: '/pages/saving/saving',
			success: function (res) {
				console.log("成功跳转到保存的记录页面");
			},
			fail: function (err) {
				console.error("跳转到保存的记录页面失败", err);
			}
		});
	},
	navigateToFeedback: function () {
		wx.navigateTo({
			url: '/pages/feedback/feedback',
			success: function (res) {
				console.log("成功跳转到问题反馈页面");
			},
			fail: function (err) {
				console.error("跳转到问题反馈页面失败", err);
			}
		});
	},
	showClearRecordsModal: function () {
		wx.showModal({
			title: '确认清空记录',
			content: '您确定要清空所有记录吗？',
			cancelText: '取消',
			confirmText: '确认',
			success: function (res) {
				if (res.confirm) {
					console.log('用户点击了确认');
				} else if (res.cancel) {
					console.log('用户点击了取消');
				}
			}
		});
	},
	onShow() {
		if (typeof this.getTabBar === 'function' && this.getTabBar()) {
			this.getTabBar().setData({
				selected: 1
			})
		}
	},

})